home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / mega src / Source / ps.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-11  |  2.0 KB  |  86 lines  |  [TEXT/KAHL]

  1. /* ========== the commmand file: ==========
  2.  
  3.     ps.c
  4.     
  5.     Copyright (c) 1993,1994 Newport Software Development
  6.     
  7.     You may distribute unmodified copies of this file for
  8.     noncommercial purposes.  You may use this file as a
  9.     reference when writing your own nShell(tm) commands.
  10.     
  11.     All other rights are reserved.
  12.     
  13.    ========== the commmand file: ========== */
  14.  
  15. #include <GestaltEqu.h>
  16. #include <Processes.h>
  17.  
  18. #include "nshc.h"
  19.                     
  20. #include "nshc_utl.proto.h"
  21.  
  22. int    Pre7( void );
  23.  
  24. int    Pre7( void )
  25. {
  26.     OSErr    error;
  27.     long    response;
  28.     
  29.     if ( error = Gestalt( 'sysv', &response ) )
  30.         return(true);
  31.         
  32.     if ( response < 0x700 )
  33.         return(true);
  34.     else
  35.         return(false);
  36. }
  37.  
  38.                     
  39. void main(t_nshc_parms *nshc_parms, t_nshc_calls *nshc_calls)
  40. {
  41.     char                    got_one;
  42.     Str255                    name;
  43.     ProcessSerialNumber        psn_p;
  44.     ProcessInfoRec          pi;
  45.     OSErr                    error;
  46.     long                    response;
  47.     
  48.     if (nshc_bad_version( nshc_parms, nshc_calls, NSHC_VERSION )) return;
  49.     
  50.     if ( Pre7() ) {
  51.         nshc_calls->NSH_putStr_err("\pThis command requires System 7.\r");
  52.         nshc_parms->result = NSHC_ERR_GENERAL;
  53.         nshc_parms->action = nsh_idle;
  54.         return;
  55.         }
  56.         
  57.     pi.processName       = name;
  58.     pi.processInfoLength = sizeof(pi);
  59.     pi.processAppSpec    = NULL;
  60.     
  61.     psn_p.highLongOfPSN = 0;
  62.     psn_p.lowLongOfPSN  = kNoProcess;
  63.     
  64.     got_one = 0;
  65.     
  66.     while(!GetNextProcess(&psn_p))
  67.         if(!GetProcessInformation(&psn_p,&pi)) {
  68.             if (!got_one) {
  69.                 nshc_calls->NSH_puts("\r Process Crea Type  Mem Size   Mem Free  Name\r");
  70.                   nshc_calls->NSH_puts(" ------- ---- ---- ---------- ---------- ----\r");
  71.                 got_one = 1;
  72.                 }
  73.             nshc_calls->NSH_printf( " %7ld", psn_p.lowLongOfPSN );
  74.             nshc_calls->NSH_printf( " %.4s %.4s", &pi.processSignature, &pi.processType );
  75.             nshc_calls->NSH_printf( " %10ld", pi.processSize );
  76.             nshc_calls->NSH_printf( " %10ld ", pi.processFreeMem );
  77.             name[++name[0]] = '\r';
  78.             nshc_calls->NSH_putStr( name );
  79.             }
  80.  
  81.     if (got_one) nshc_calls->NSH_putchar('\r');
  82.     
  83.     nshc_parms->result = !got_one;    //    success if we found any processes
  84.     nshc_parms->action = nsh_idle;
  85. }
  86.